package game.model.config 
{
	import flash.utils.Dictionary;
	/**
	 * ...
	 * @author gcxk721
	 */
	public class ConfigManager 
	{
		public static const STAGEWIDTH:Number = 1000;
		public static const STAGEHEIGHT:Number = 600;
       
        public static const CONFIG_XML_PATH:String = "assets/config/config.xml";

        public static var port:int;
        public static var resDic:Dictionary = new Dictionary();
        public static var version:String;
        public static var chatport:int;
        public static var ressizeDic:Dictionary = new Dictionary();
        public static var isFull:Boolean = false;
        public static var versionCode:int = 0;
        public static var key:int = 0;
        public static var ip:String;
        public static var parameters:Object;
        private static var _configData:XML;
        public static var rootURL:String = "";
        public static var soundDic:Dictionary;
        public static var onDebugTimer:Boolean = false;
        public static var chatport2:int;
        public static var loggerTime:int = 0;
        public static var serverId:int = 0;

        public static function getVersion():String
		{
			return (version + '3' + ConfigManager.key) + versionCode;
        }
		
        public static function get configData():XML
		{
            return _configData
        }
		
        public static function getTitle():String
		{
            //return ("醉西游");
			return 'xyfy';
        }
		
        public static function cURL(value : String):String
		{
            return ConfigManager.rootURL + value;
        }
		
        public static function setConfigData(str : String):void
		{
            _configData = new XML(str);
            key = int(ConfigManager.configData.key);
            version = ConfigManager.configData.version.toString();
            var lst:XMLList = ConfigManager.configData.file.soundList.item;
            soundDic = new Dictionary();
            var i : int;
			var j:int;
			var value : String;
            var array : Array;
            while (i < lst.length()) 
			{
                value = lst[i].toString();
                array = value.split(",");
                j = 0;
                while (j < array.length) 
				{
                    soundDic[array[j]] = lst[i].@res.toString();
                    j++;
                }
                i++;
            }
            str = null;
        }
		
        public static function codeVersion():String
		{
			return (ConfigManager.version + ConfigManager.key) + ConfigManager.versionCode;
        }
		
        public static function uiVersion(ver : String):String
		{
            ver = rURL(ver);
            if (resDic[ver] == undefined)
			{
                return String(Math.random());
            }
			return resDic[ver] + "_" + ConfigManager.version + "_" + versionCode;
        }
		
        public static function setIPConfigData():void
		{
            ip = ConfigManager.parameters.ip;
            port = int(ConfigManager.parameters.port);
            chatport = int(ConfigManager.parameters.port2);
            chatport2 = int(ConfigManager.parameters.port3);
            rootURL = ConfigManager.parameters.game_cdn;
            isFull = Boolean(int(ConfigManager.parameters.full));
        }
		
        public static function resVersion(res : String):String
		{
            res = rURL(res);
            if (resDic[res] == undefined)
			{
                return null;
            }
            return resDic[res] + "4";
        }
		
	}

}